Corrigindo um bug ao atualizar o push name no evento MESSAGES_UPSERT e MESSAGES_UPDATE#1366
Merged
DavidsonGomes merged 2 commits intoEvolutionAPI:developfrom Apr 14, 2025
Merged
Conversation
…der to return always the chatname from the user correctly
Contributor
Reviewer's Guide by SourceryThis pull request fixes a bug where the Sequence diagram for MESSAGES_UPSERT eventsequenceDiagram
participant WhatsApp
participant BaileysService
participant PrismaRepository
participant WebhookService
WhatsApp->>BaileysService: Event: MESSAGES_UPSERT (message received)
BaileysService->>BaileysService: Check if chat exists
alt Chat exists and pushName is valid and fromMe is false and not a group
BaileysService->>PrismaRepository: Update Chat.name with pushName
PrismaRepository-->>BaileysService: Success
BaileysService->>WebhookService: Send CHATS_UPSERT event with updated Chat
WebhookService-->>BaileysService: Acknowledged
else Chat does not exist or pushName is invalid or fromMe is true or is a group
BaileysService->>BaileysService: Do not update Chat.name
end
Updated class diagram for ChatclassDiagram
class Chat {
remoteJid: string
instanceId: string
unreadMessages: number
// name: string - Removed from initial creation
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey @pedro-php - I've reviewed your changes - here's some feedback:
Overall Comments:
- The changes look good, but it would be helpful to add a comment explaining why the
namefield is no longer updated during theMESSAGES_UPDATEevent. - Consider adding a test case to specifically verify that the chat name is updated correctly when a new message is received from a contact.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
|
Talvez vc consiga resolver este bug também: #1367 chegou a ocorrer com vc? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
Problema
Ao enviar uma mensagem via dispositivo, dois comportamentos distintos ocorriam:
MESSAGES_UPSERTatualizava o camponameda tabelaChatcom opushnamedo remetente.MESSAGES_UPDATEsobrescrevia o camponamecom uma string vazia de forma consistente, pois tentava fazer umupdateutilizando uma variável que sequer era definida — já que esse campo não era enviado pelo respectivo evento da Baileys.O que foi alterado?
nameda tabelaChatnão é mais atualizado durante o eventoMESSAGES_UPDATE. Isto ocorre pois o camponamesequer é enviado no evento, causando ele sempre ser atualizado como uma string vazia.MESSAGES_UPSERT, o camponamesó é atualizado quandofromMefor falso, ou seja, apenas quando a mensagem for recebida (não enviada pelo próprio usuário).Resolução
Agora, ao chamar um endpoint que retorna o campo
nameda tabelaChat(como o/chat/findChats/), o valor retornado será o correto — evitando strings vazias ou o nome do próprio remetente. O campo continua sendo atualizado normalmente ao receber mensagens.Summary by Sourcery
Fix the behavior of updating chat names during message events to prevent incorrect name updates
Bug Fixes:
Enhancements: